package cn.ffcs.uec.outStaffCorrectApply.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Components;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.event.ForwardEvent;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.Messagebox;

import cn.ffcs.raptornuke.plugin.common.zk.ctrl.BasePortletComposer;
import cn.ffcs.raptornuke.plugin.common.zk.util.ZkUtil;
import cn.ffcs.raptornuke.portal.theme.ThemeDisplay;
import cn.ffcs.uec.common.manager.CustomFilesManager;
import cn.ffcs.uec.common.util.NodeVoUtil;
import cn.ffcs.uec.common.util.UecConstants;
import cn.ffcs.uec.common.vo.UecBdPsncl;
import cn.ffcs.uec.organization.manager.UecOrgDeptManager;
import cn.ffcs.uec.organization.manager.UecOrgOrgsManager;
import cn.ffcs.uec.organization.model.UecOrgDept;
import cn.ffcs.uec.organization.vo.OrganizationRelationVo;
import cn.ffcs.uec.outStaff.manager.UecOutStaffManager;
import cn.ffcs.uec.outStaff.model.UecOutStaffInfo;
import cn.ffcs.uec.outStaffCorrectApply.action.bean.OutStaffCorrectApprovalViewMainBean;
import cn.ffcs.uec.post.manager.UecPostManager;
import cn.ffcs.uec.post.model.UecPost;
import cn.ffcs.uec.recordsApproval.constant.ApprovalConstants;
import cn.ffcs.uec.recordsApproval.manager.ActRunTaskManager;
import cn.ffcs.uec.recordsApproval.util.ApprovalUtil;
import cn.ffcs.uec.staff.manager.UecPsnjobManager;
import cn.ffcs.uec.staff.manager.UecTrialManager;
import cn.ffcs.uec.staff.model.UecPsnjob;
import cn.ffcs.uec.staff.model.UecTrial;
import cn.ffcs.uec.staffRecords.vo.AtiOaBaseObject;
import cn.ffcs.uom.common.model.DefaultDaoFactory;
import cn.ffcs.uom.common.util.ApplicationContextUtil;
import cn.ffcs.uom.common.util.DateUtil;
import cn.ffcs.uom.common.util.ListboxUtils;
import cn.ffcs.uom.common.util.PlatformUtil;
import cn.ffcs.uom.common.util.PubUtil;
import cn.ffcs.uom.common.util.StrUtil;
import cn.ffcs.uom.common.vo.NodeVo;

/**
 * 外包转正审批弹框
 * 
 * @author liuxiaodong
 *
 */
@Controller
@Scope("prototype")
public class OutStaffCorrectApprovalViewMainComposer extends BasePortletComposer {

	private static final long serialVersionUID = -7835821366173944090L;

	private OutStaffCorrectApprovalViewMainBean bean = new OutStaffCorrectApprovalViewMainBean();

	private UecOutStaffManager uecOutStaffManager = (UecOutStaffManager) ApplicationContextUtil
			.getBean("uecOutStaffManager");

	private UecOrgOrgsManager uecOrgOrgsManager = (UecOrgOrgsManager) ApplicationContextUtil
			.getBean("uecOrgOrgsManager");

	private UecTrialManager uecTrialManager = (UecTrialManager) ApplicationContextUtil.getBean("uecTrialManager");

	private UecPsnjobManager uecPsnjobManager = (UecPsnjobManager) ApplicationContextUtil.getBean("uecPsnjobManager");

	private UecOrgDeptManager uecOrgDeptManager = (UecOrgDeptManager) ApplicationContextUtil
			.getBean("uecOrgDeptManager");

	private UecPostManager uecPostManager = (UecPostManager) ApplicationContextUtil.getBean("uecPostManager");

	private ActRunTaskManager actRunTaskManager = (ActRunTaskManager) ApplicationContextUtil
			.getBean("actRunTaskManager");

	private CustomFilesManager customFilesManager = (CustomFilesManager) ApplicationContextUtil
			.getBean("customFilesManager");

	private String taskDefKey;

	private UecOutStaffInfo outStaffInfo = UecOutStaffInfo.newInstance();

	private UecTrial trial = UecTrial.newInstance();

	private UecPsnjob uecPsnjob = UecPsnjob.newInstance();

	/**
	 * 部门
	 */
	private UecOrgDept findUecOrgDept;

	/**
	 * 岗位
	 */
	private UecPost uecPost;

	/**
	 * 岗位序列
	 */
	private String postSequence = null;
	/**
	 * 选择的组织
	 */
	private OrganizationRelationVo organization;
	/**
	 * 人员类别
	 */
	private UecBdPsncl uecBdPsnclTree;

	/**
	 * 任职信息更新、新增标志
	 */
	@SuppressWarnings("unused")
	private boolean uecPsnjobFalg = false;

	private String opType;

	private String taskId;

	private AtiOaBaseObject oaBaseObject;

	@Override
	public String getPortletId() {
		return super.getPortletId();
	}

	@Override
	public ThemeDisplay getThemeDisplay() {
		return super.getThemeDisplay();
	}

	public void doAfterCompose(Component comp) throws Exception {
		super.doAfterCompose(comp);
		Components.wireVariables(comp, bean);

		this.bean.getUecPostBandboxExt().addForward("onUecPostEditSelected", comp, "onUecPostEditSelectedResponse");
		this.bean.getOutStaffPkDept().addForward("onGetOrganization", comp, "onGetOrganizationResponse");

		this.bean.getOutPsncl().addForward("onGetBdPsncl", comp, "onGetBdPsnclResponse");
	}

	/**
	 * 界面初始化
	 */
	public void onCreate$outStaffCorrectApprovalViewMainWin() {
		bandListbox();
		bindBean();
		bean.getUecPostBandboxExt().setDisabled(true);
	}

	/**
	 * 监听人员类别组织树
	 */
	public void onGetBdPsnclResponse(final ForwardEvent event) {
		if (event.getOrigin().getData() != null) {
			uecBdPsnclTree = (UecBdPsncl) event.getOrigin().getData();
		}
	}

	/**
	 * 监听UecOrgPostBandboxExt传出的事件
	 * 
	 * @param event
	 */
	public void onUecPostEditSelectedResponse(final ForwardEvent event) {
		if (event.getOrigin().getData() != null) {
			uecPost = (UecPost) event.getOrigin().getData();
			if (null != uecPost) {
				bean.getUecPostBandboxExt().setValue(uecPost.getPostname());
				// 岗位序列
				postSequence = uecPost.getPkPostseries();
				// 岗位序列 --页面赋值
				if ("1001A1100000000006R2".equals(postSequence)) {
					bean.getPkPostseries().setValue("管理序列");
				} else if ("1001A1100000000006R3".equals(postSequence)) {
					bean.getPkPostseries().setValue("专业序列");
				}
			}
		}
	}

	/**
	 * 监听组织树插件抛出的事件
	 * 
	 * @param event
	 */
	public void onGetOrganizationResponse(final ForwardEvent event) {
		if (event.getOrigin().getData() != null) {
			organization = (OrganizationRelationVo) event.getOrigin().getData();
			if ("ORG".equals(organization.getOrgType())) {
				ZkUtil.showError("转正后部门选项请选择到部门层级!", "错误提示");
				bean.getOutStaffPkDept().setValue(null);
				bean.getHrorg().setValue(null);
				bean.getUecPostBandboxExt().setValue(null);
				bean.getPkPostseries().setValue(null);
				bean.getUecPostBandboxExt().setDisabled(true);
				return;
			} else {
				bean.getUecPostBandboxExt().setDisabled(false);
				bean.getPkPostseries().setValue(null);
				// 根据部门主键：pkorg，找到该部门所在的公司
				findUecOrgDept = new UecOrgDept();
				findUecOrgDept.setPkDept(organization.getOrg());
				findUecOrgDept = uecOrgDeptManager.findUecOrgDeptByOrgDept(findUecOrgDept);
				if (null != findUecOrgDept) {
					uecPsnjobFalg = true;
					bean.getHrorg().setValue(uecOrgOrgsManager.getUecOrgOrgsNameByPkOrg(findUecOrgDept.getPkOrg()));
					bean.getUecPostBandboxExt().setValue(null);
					Events.postEvent("onUecDeptSelect",
							this.bean.getUecPostBandboxExt().getBean().getUecPostListboxExt(), findUecOrgDept);
				} else {
					uecPsnjobFalg = false;
				}
			}
		}
	}

	/**
	 * 重新申请
	 * 
	 * @throws InterruptedException
	 */
	public void onOk() throws InterruptedException {
		if (!"onView".equals(opType)) {
			// 判断任务是否已被处理
			boolean isCompleted = ApprovalUtil.isTaskCompleted(oaBaseObject, taskId);
			if (isCompleted) {
				onCancel();
				Events.postEvent(ApprovalConstants.ON_REFRESH_QUERY_RESPONSE, this.self, null);
				ZkUtil.showError("任务不存在或已被处理完毕！", "错误提示");
				return;
			}
			// 数据校验
			String msg = this.checkUacStaffData();
			if (null != msg) {
				Messagebox.show(msg);
				return;
			}
			Messagebox.show("是否提交审批？", "输入确认提示", Messagebox.OK | Messagebox.CANCEL, Messagebox.QUESTION,
					new EventListener() {
						@Override
						public void onEvent(Event event) throws Exception {
							if (((Integer) event.getData()).intValue() == Messagebox.OK) {
								postApprovalData();
								onCancel();
							} else {
								return;
							}
						}
					});
		} else {
			this.onCancel();
		}

	}

	/**
	 * 提交审批数据
	 * 
	 * @throws InterruptedException
	 */
	public void postApprovalData() throws InterruptedException {

		// 试用结果
		trial.setTrialresult(Long.valueOf((String) bean.getTrialresult().getSelectedItem().getValue()));
		// 试用日期
		trial.setRegulardate(DateUtil.dateToStr(bean.getRegulardate().getValue()));

		String currentName = PlatformUtil.getCurrentUser().getScreenName();
		trial.setModifier(currentName);
		trial.setModifiedtime(DateUtil.dateToStr(DateUtil.getNewDate()));
		DefaultDaoFactory.getDefaultDao().updateObject(trial);

		if (null != findUecOrgDept) {
			// 如果组织发生变动
			if (!outStaffInfo.getPkHrorg().equals(findUecOrgDept.getPkOrg())) {
				outStaffInfo.setPkHrorg(findUecOrgDept.getPkOrg());
				outStaffInfo.setModifier(currentName);
				outStaffInfo.setModifiedTime(DateUtil.getCurrenDate());
				DefaultDaoFactory.getDefaultDao().updateObject(outStaffInfo);
			}
			uecPsnjob.setPkOrg(findUecOrgDept.getPkOrg());
			uecPsnjob.setPkHrorg(findUecOrgDept.getPkOrg());
			uecPsnjob.setPkDept(findUecOrgDept.getPkDept());
		}
		// 人员类别
		if (null != uecBdPsnclTree) {
			String pkpsncl = uecBdPsnclTree.getPkPsncl();
			uecPsnjob.setPkPsncl(pkpsncl);
		}
		// 职务名称
		uecPsnjob.setJobglbdef4(bean.getJobglbdef4().getValue());
		// 任职原因
		uecPsnjob.setJobglbdef5(bean.getJobglbdef5().getValue());
		// 任职文号
		uecPsnjob.setJobglbdef6(bean.getJobglbdef6().getValue());
		// 岗位等级
		uecPsnjob.setJobglbdef3((String) bean.getJobglbdef3().getSelectedItem().getValue());
		// 岗位层级
		uecPsnjob.setJobglbdef2((String) bean.getJobglbdef2().getSelectedItem().getValue());

		// 岗位序列
		if (null != postSequence) {
			uecPsnjob.setPkPostseries(postSequence);
		}
		// 生效日期
		uecPsnjob.setBegindate(DateUtil.dateToStr(bean.getEffectDate().getValue()));

		// 更新结束时间 uec_trial , uec_psnjob 字段 begindate,enddate重复
		uecPsnjob.setEnddate(null);
		// 任本岗位层级时间
		uecPsnjob.setJobglbdef14(DateUtil.dateToStr(bean.getJobglbdef14().getValue()));
		// 任现岗位层级时间
		uecPsnjob.setJobglbdef8(DateUtil.dateToStr(bean.getJobglbdef8().getValue()));

		uecPsnjob.setModifier(currentName);
		uecPsnjob.setModifiedtime(DateUtil.getCurrenDate());
		if (null != uecPost) {
			uecPsnjob.setPkPost(uecPost.getPkPost());
		}
		DefaultDaoFactory.getDefaultDao().updateObject(uecPsnjob);

		Events.postEvent("onOKResponse", this.self, ApprovalConstants.ON_OK_RESULT);
	}

	/**
	 * 审批同意
	 * 
	 * @throws InterruptedException
	 */
	public void onApproval() throws InterruptedException {
		Messagebox.show("是否提交审批？", "输入确认提示", Messagebox.OK | Messagebox.CANCEL, Messagebox.QUESTION,
				new EventListener() {
					@Override
					public void onEvent(Event event) throws Exception {
						if (((Integer) event.getData()).intValue() == Messagebox.OK) {
							approvalData();
						} else {
							return;
						}
					}
				});
	}

	/**
	 * 审批数据
	 * 
	 * @throws InterruptedException
	 */
	public void approvalData() throws InterruptedException {
		Map<String, Object> map = new HashMap<String, Object>();
		String comment = this.getComment(taskDefKey);
		map.put("comment", comment);
		map.put("onApprovalResult", ApprovalConstants.ON_APPROVAL_RESULT);
		Events.postEvent("onApprovalResponse", this.self, map);
		this.onCancel();
	}

	/**
	 * 审批拒绝
	 */
	public void onReject() {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("comment", this.getComment(taskDefKey));
		map.put("onRejectResult", ApprovalConstants.ON_REJECT_RESULT);
		Events.postEvent("onRejectResponse", this.self, map);
		this.onCancel();
	}

	/**
	 * 取消
	 */
	public void onCancel() {
		this.bean.getOutStaffCorrectApprovalViewMainWin().onClose();
	}

	/**
	 * 获取传值
	 */
	private void bindBean() {
		String procDefName = (String) arg.get("procDefName");
		this.bean.getOutStaffCorrectApprovalViewMainWin().setTitle(procDefName + "审批");
		oaBaseObject = (AtiOaBaseObject) arg.get("oaBaseObject");
		if (!StrUtil.isNullOrEmpty(oaBaseObject)) {
			// 获取审批意见
			PubUtil.fillBeanFromPo(oaBaseObject, bean);
		}
		opType = (String) arg.get("opType");
		if ("onView".equals(opType)) {
			// 查看历史工单
			setButtonValid(true, false, false);
			setTextValid(true, true, true);
		} else {
			taskDefKey = (String) arg.get("taskDefKey");
			if ("modify".equals(taskDefKey)) {
				setButtonValid(true, false, false);
				setTextValid(false, false, false);
			} else {
				setButtonValid(false, true, true);
			}
			if ("deptLeaderAudit".equals(taskDefKey)) {
				this.bean.getSecondText().setRows(2);
				this.setTextValid(true, false, false);
				bean.getSecondText().setValue(null);
			}
			if ("hrAudit".equals(taskDefKey)) {
				this.bean.getThirdText().setRows(2);
				this.setTextValid(false, true, false);
				bean.getThirdText().setValue(null);
			}
			if ("hrLeaderAudit".equals(taskDefKey)) {
				this.bean.getFourthText().setRows(2);
				this.setTextValid(false, false, true);
				bean.getFourthText().setValue(null);
			}
		}

		taskId = (String) arg.get("taskId");
		if (!StrUtil.isNullOrEmpty(oaBaseObject)) {

			List<Map<String, Object>> list = actRunTaskManager.getRuTasks(oaBaseObject.getProcInstId());
			if (null == list) {
				ZkUtil.showError("未知错误!", "错误信息");
				return;
			}
			if (list.size() == 0) {
				String outStaffIdTmp = oaBaseObject.getOutStaffId();
				oaBaseObject.setOutStaffId(oaBaseObject.getOutStaffIdHis());
				oaBaseObject.setOutStaffIdHis(outStaffIdTmp);

				String trialIdTmp = oaBaseObject.getTrialId();
				oaBaseObject.setTrialId(oaBaseObject.getTrialIdHis());
				oaBaseObject.setTrialIdHis(trialIdTmp);

			}

			// 获取转正历史对比信息
			// 获取人员信息
			outStaffInfo.setOutStaffId(Long.valueOf(oaBaseObject.getOutStaffIdHis()));
			outStaffInfo = uecOutStaffManager.findUecOutStaffInfoByOutStaffId(outStaffInfo);
			if (null != outStaffInfo) {
				// 转正人员编码
				bean.getPsnCode().setValue(outStaffInfo.getPsnCode());
				// 转正人员姓名
				bean.getPsnName().setValue(outStaffInfo.getPsnName());
			}

			String psnjobIdHis = oaBaseObject.getPsnjobIdHis();
			if (!StrUtil.isNullOrEmpty(psnjobIdHis)) {
				uecPsnjob.setPsnjobId(Long.valueOf(psnjobIdHis));
				uecPsnjob = uecPsnjobManager.findUecPsnjobById(uecPsnjob);
				if (null != uecPsnjob) {
					// 组织
					bean.getOrgName().setValue(uecOrgOrgsManager.getUecOrgOrgsNameByPkOrg(uecPsnjob.getPkOrg()));
					// 部门
					bean.getDeptName().setValue(uecOrgDeptManager.getUecOrgDeptNameByPkDept(uecPsnjob.getPkDept()));
					// 岗位
					if (!StrUtil.isNullOrEmpty(uecPsnjob.getPkPost())) {
						UecPost uecPost = UecPost.newInstance();
						uecPost.setPkPost(uecPsnjob.getPkPost());
						uecPost = uecPostManager.queryUecPost(uecPost);
						if (null != uecPost) {
							bean.getPostName().setValue(uecPost.getPostname());
						}
					} else {
						bean.getPostName().setValue(uecPsnjob.getOutJobName());
					}

					// 人员类别
					UecBdPsncl uecBdPsncl = new UecBdPsncl();
					uecBdPsncl.setPkPsncl(uecPsnjob.getPkPsncl());
					uecBdPsncl = customFilesManager.findUecUecBdPsnclByUecBdPsncl(uecBdPsncl);
					if (!StrUtil.isNullOrEmpty(uecBdPsncl)) {
						bean.getPersonnelCategory().setValue(uecBdPsncl.getName());
					}
					// 岗位序列
					if ("1001A1100000000006R3".equals(uecPsnjob.getPkPostseries())) {
						bean.getPostSequence().setValue("专业序列");
					} else if ("1001A1100000000006R2".equals(uecPsnjob.getPkPostseries())) {
						bean.getPostSequence().setValue("管理序列");
					} else {
						bean.getPostSequence().setValue(null);
					}
					// 岗位层级
					bean.getPostLevel()
							.setValue(customFilesManager.findCustomFilesByPkdefdoc(uecPsnjob.getJobglbdef2()));
					// 岗位等级
					bean.getPostGrade()
							.setValue(customFilesManager.findCustomFilesByPkdefdoc(uecPsnjob.getJobglbdef3()));
					// 职务名称
					bean.getPositionName().setValue(uecPsnjob.getJobglbdef4());
					// 任职原因
					bean.getAppointmentReason().setValue(uecPsnjob.getJobglbdef5());
					// 任职文号
					bean.getAppointmentNumber().setValue(uecPsnjob.getJobglbdef6());
					// 任本岗位层级时间
					bean.getRenaultLevelTime().setValue(uecPsnjob.getJobglbdef8());
					// 任现岗位层级时间
					bean.getRenaultGradeTime().setValue(uecPsnjob.getJobglbdef14());
				}
			}

			// 审批 信息
			// 获取 审批转正部门
			String psnjobIdAdd = oaBaseObject.getPsnjobIdAdd();
			if (!StrUtil.isNullOrEmpty(psnjobIdAdd)) {
				uecPsnjob = UecPsnjob.newInstance();
				uecPsnjob.setPsnjobId(Long.valueOf(psnjobIdAdd));
				uecPsnjob = uecPsnjobManager.findUecPsnjobById(uecPsnjob);
				if (null != uecPsnjob) {
					PubUtil.fillBeanFromPo(uecPsnjob, bean);
					// 生效日期 psnjobAdd 开始时间
					bean.getEffectDate().setValue(DateUtil.patternStrToDate(uecPsnjob.getBegindate()));
					// 部门
					if (!StrUtil.isNullOrEmpty(uecPsnjob.getPkDept())) {
						bean.getHrorg().setValue(uecOrgOrgsManager.getUecOrgOrgsNameByPkOrg(uecPsnjob.getPkOrg()));
						bean.getOutStaffPkDept()
								.setValue(uecOrgDeptManager.getUecOrgDeptNameByPkDept(uecPsnjob.getPkDept()));
					} else {
						bean.getOutStaffPkDept().setValue(null);
					}

					// 岗位
					if (!StrUtil.isNullOrEmpty(uecPsnjob.getPkPost())) {
						UecPost uecPost = UecPost.newInstance();
						uecPost.setPkPost(uecPsnjob.getPkPost());
						uecPost = uecPostManager.queryUecPost(uecPost);
						if (null != uecPost) {
							bean.getUecPostBandboxExt().setValue(uecPost.getPostname());
						}
					} else {
						bean.getUecPostBandboxExt().setValue(uecPsnjob.getOutJobName());
					}

					UecBdPsncl uecBdPsncl = new UecBdPsncl();
					uecBdPsncl.setPkPsncl(uecPsnjob.getPkPsncl());
					uecBdPsncl = customFilesManager.findUecUecBdPsnclByUecBdPsncl(uecBdPsncl);
					if (!StrUtil.isNullOrEmpty(uecBdPsncl)) {
						bean.getOutPsncl().setValue(uecBdPsncl.getName());
					}
					// 岗位序列
					if ("1001A1100000000006R3".equals(uecPsnjob.getPkPostseries())) {
						bean.getPkPostseries().setValue("专业序列");
					} else if ("1001A1100000000006R2".equals(uecPsnjob.getPkPostseries())) {
						bean.getPkPostseries().setValue("管理序列");
					} else {
						bean.getPkPostseries().setValue(null);
					}

					// 任本岗位层级时间
					bean.getJobglbdef8().setValue(DateUtil.patternStrToDate(uecPsnjob.getJobglbdef8()));
					// 任现岗位层级时间
					bean.getJobglbdef14().setValue(DateUtil.patternStrToDate(uecPsnjob.getJobglbdef14()));
				}

			}

			// 试用信息
			String trialId = oaBaseObject.getTrialId();
			if (!StrUtil.isNullOrEmpty(trialId)) {
				// 获取审批试用信息
				trial = UecTrial.newInstance();
				trial.setTrialId(Long.parseLong(trialId));
				trial = uecTrialManager.findUecTrialById(trial);
				if (null != trial) {
					// 试用结果
					@SuppressWarnings("unchecked")
					List<Listitem> trialresultItem = bean.getTrialresult().getChildren();
					for (Listitem listitem : trialresultItem) {
						if (null != listitem && !StrUtil.isNullOrEmpty(listitem.getValue())
								&& !StrUtil.isNullOrEmpty(trial.getTrialresult())) {
							if (listitem.getValue().toString().equals(trial.getTrialresult().toString())) {
								bean.getTrialresult().setSelectedItem(listitem);
							}
						}
					}

					// 试用类型
					if (trial.getTrialType() == 1L) {
						bean.getTrialTypeName().setValue("转岗试用");
					} else if (trial.getTrialType() == 2L) {
						bean.getTrialTypeName().setValue("入职试用");
					}
					// 试用开始日期
					bean.getTrialBegindate().setValue(trial.getBegindate());
					// 试用结束日期
					bean.getTrialEnddate().setValue(trial.getEnddate());
					// 转正日期
					bean.getRegulardate().setValue(DateUtil.patternStrToDate(trial.getRegulardate()));
				}

			}

		}

	}

	/**
	 * 获取审批意见
	 * 
	 * @param taskDefKey
	 * @return
	 */
	private String getComment(String taskDefKey) {
		if ("deptLeaderAudit".equals(taskDefKey)) {
			return this.bean.getSecondText().getValue();
		}
		if ("hrAudit".equals(taskDefKey)) {
			return this.bean.getThirdText().getValue();
		}
		if ("hrLeaderAudit".equals(taskDefKey)) {
			return this.bean.getFourthText().getValue();
		}
		return null;
	}

	/**
	 * 设置按钮
	 * 
	 * @param canEdit
	 * @param canApproval
	 * @param canReject
	 */
	private void setButtonValid(boolean canEdit, boolean canApproval, boolean canReject) {
		this.bean.getOkBtn().setVisible(canEdit);
		this.bean.getOkBtn().setDisabled(!canEdit);

		this.bean.getApprovalBtn().setVisible(canApproval);
		this.bean.getApprovalBtn().setDisabled(!canApproval);

		this.bean.getRejectBtn().setVisible(canReject);
		this.bean.getRejectBtn().setDisabled(!canReject);

	}

	/**
	 * 设置审批意见栏
	 * 
	 * @param secondCanEdit
	 * @param thirdCanEdit
	 * @param fourthCanEdit
	 */
	private void setTextValid(boolean secondCanEdit, boolean thirdCanEdit, boolean fourthCanEdit) {
		this.bean.getSecondText().setDisabled(!secondCanEdit);
		this.bean.getThirdText().setDisabled(!thirdCanEdit);
		this.bean.getFourthText().setDisabled(!fourthCanEdit);
	}

	/**
	 * 检测填入的参数是否为空
	 */
	public String checkUacStaffData() {
		if (StrUtil.isNullOrEmpty(bean.getTrialresult().getSelectedItem().getValue())) {
			return "请选择试用结果";
		} else if (StrUtil.isNullOrEmpty(bean.getRegulardate().getValue())) {
			return "请选择转正日期";
		} else if (StrUtil.isNullOrEmpty(bean.getEffectDate().getValue())) {
			return "请选择生效日期";
		} else if (StrUtil.isNullOrEmpty(bean.getOutStaffPkDept().getValue())) {
			return "请选择部门";
		} else if (StrUtil.isNullOrEmpty(bean.getUecPostBandboxExt().getValue())) {
			return "请选择岗位";
		} else if (StrUtil.isNullOrEmpty(bean.getOutPsncl().getValue())) {
			return "请选择人员类别";
		} else if (StrUtil.isNullOrEmpty(bean.getJobglbdef2().getSelectedItem().getValue())) {
			return "请选择岗位层级";
		} else if (StrUtil.isNullOrEmpty(bean.getJobglbdef3().getSelectedItem().getValue())) {
			return "请选择岗位等级";
		}
		return null;
	}

	/**
	 * 绑定Listbox
	 */
	public void bandListbox() {
		// 试用类型trialType
		List<NodeVo> nodeVoTrialTypeList = new ArrayList<NodeVo>();
		String[][] trialType = { { "1", "入职试用" }, { "2", "转岗试用" } };
		for (int i = 0; i < trialType.length; i++) {
			NodeVo nodeVo = new NodeVo();
			for (int j = 0; j < 1; j++) {
				nodeVo.setId(trialType[i][j]);
				nodeVo.setName(trialType[i][j + 1]);
			}
			nodeVoTrialTypeList.add(nodeVo);
		}
		ListboxUtils.rendererForEdit(bean.getTrialType(), nodeVoTrialTypeList);

		// 试用结果trialresult
		List<NodeVo> nodeVoResultList = new ArrayList<NodeVo>();
		String[][] trialresult = { { "1", "转正" }, { "2", "延长试用期" }, { "3", "未通过试用" } };
		for (int i = 0; i < trialresult.length; i++) {
			NodeVo nodeVo = new NodeVo();
			for (int j = 0; j < 1; j++) {
				nodeVo.setId(trialresult[i][j]);
				nodeVo.setName(trialresult[i][j + 1]);
			}
			nodeVoResultList.add(nodeVo);
		}
		ListboxUtils.rendererForEdit(bean.getTrialresult(), nodeVoResultList);
		// 岗位层级--JOBGLBDEF2
		ListboxUtils.rendererForEdit(bean.getJobglbdef2(), NodeVoUtil.getDictionaries(UecConstants.POST_HIERARCHY));
		// 岗位等级--Jobglbdef3
		ListboxUtils.rendererForEdit(bean.getJobglbdef3(), NodeVoUtil.getDictionaries(UecConstants.POST_LEVEL));
	}

}
